package cn.com.wdjedu.androidapp.wjeduandroid.ui.societyfragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.wdjedu.androidapp.wjeduandroid.R;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.MvpFragment;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.society.SocietyPresenter;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.society.Societyview;

/**
 * Created by CCY on 2017/2/8.
 */
public class SocietyFragment extends MvpFragment<SocietyPresenter> implements Societyview {

    @BindView(R.id.homepageView)
    WebView homepageView;
    private View view;
    private static final String FRAGMENT_SOCIETY = "fragment_society";


    /**
     * 标志位，标志已经初始化完成
     */
    private boolean isPrepared;

    /**
     * 创建新实例
     *
     * @param index
     * @return
     */
    public static SocietyFragment newInstance(int index) {
        Bundle bundle = new Bundle();
        bundle.putInt(FRAGMENT_SOCIETY, index);
        SocietyFragment fragment = new SocietyFragment();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_society, null);
            ButterKnife.bind(this, view);
            //获得索引值
            Bundle bundle = getArguments();
            if (bundle != null) {
                int mCurIndex = bundle.getInt(FRAGMENT_SOCIETY);
            }
            isPrepared = true;
            lazyLoad();
        }
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }

//        initFunc();
//        initView(view);

        ButterKnife.bind(this, view);
        homepageView.loadUrl("http://www.xueshenx.com/");
        WebSettings settings = homepageView.getSettings();
//        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        return view;
    }


    @Override
    protected void onInvisible() {
        //初始化界面
        if (view != null) {


        }
        super.onInvisible();
    }


    @Override
    protected void lazyLoad() {
        if (!isPrepared || !isVisible) {
            return;
        }

    }

    @Override
    public void onResume() {
        super.onResume();

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showError(String error) {

    }

    @Override
    protected SocietyPresenter createPresenter() {
        return null;
    }
}
